﻿@using Lavka.Core
@using Lavka.Models
<div id="AddArticle">
    <select id="ddlArticles">
        @foreach (Articles art in ArticlesHelper.GetArticles(new LavkaDbEntities()))
        {
            <option value="@art.ArticleId">@art.Title</option>
        }
    </select>
    <input type="button" value="Сохранить" class="button" name="btnSaveArticle" id="btnSaveArticle" />
</div>

<script type="text/javascript">
    $(function () 
    {
        $("#btnSaveArticle").click(function (event) 
        {
            if ($("select#ddlArticles").val() != -1) 
            {
                $.ajax({ url: "/products/AddArticle",
                    type: 'POST',
                    data: { articleId: $("select#ddlArticles").val() },
                    success: function (responce) 
                    {
                        $("#ArticlesList").replaceWith(responce)
                    },
                    error: function (xhr) 
                    {
                        alert("Ошибка!");
                    }

                });
            }
        });
    })
</script>